package algorithms.strings


import org.junit.jupiter.api.Test
import redirectSystemIn
import redirectSystemOut
import java.util.*
import kotlin.test.assertEquals

class MorganAndStringTests {
    @Test
    fun morganAndStringTest() {
        redirectSystemIn(this.javaClass) {
            val scan = Scanner(System.`in`)
            redirectSystemOut {
                while (scan.hasNextLine()) {
                    val t = scan.nextLine().trim().toInt()

                    for (tItr in 1..t) {
                        val a = scan.nextLine()

                        val b = scan.nextLine()

                        val result = morganAndString(a, b)

                        println(result)
                    }
                    for (tItr in 1..t) {
                        it.add(scan.nextLine().trim())
                    }
                }
            }
        }
    }

    @Test
    fun test1() {
        val reader = javaClass.getResourceAsStream("/MorganAndStringTests/1.txt").reader()
        val lines = reader.readLines().map { it.trim() }
        val a = lines[0]
        val b = lines[1]

        val result = morganAndString(a, b)
        val expected = lines[2]

        assertEquals(expected, result)
    }

    @Test
    fun test2() {
        val reader = javaClass.getResourceAsStream("/MorganAndStringTests/2.txt").reader()
        val lines = reader.readLines().map { it.trim() }
        val a = lines[0]
        val b = lines[1]

        val result = morganAndString(a, b)
        val expected = lines[2]

        assertEquals(expected, result)
    }
}